<template>
  <div ref="chart" style="width: 100%;height:300px; "></div>
</template>

<script>
// 引入ECharts主模块
import * as echarts from 'echarts';
import {infoArea} from "@/api/combatUser/alarmInformation";

export default {
  name: 'trendChart',
  data: function () {
    return {
      initData: [],
      xAxis: [],
      series: []
    }
  },
  async mounted() {
    //发送网络请求获取数据
    let res = await infoArea();
    if (res.code == '200') {
      this.xAxis = res.data.map(item => item.province);
      this.series = res.data.map(item => item.count);
    }
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(this.$refs.chart);

    // 指定图表的配置项和数据
    var option = {
      title: {
        text: '按照省份统计',
        left: 'center', // 标题位置
        textStyle: {
          color: '#333', // 标题颜色
          fontSize: 16 // 标题字体大小
        }
      },
      color: ["#4285F4", "#00B042"],
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "cross",
          label: {
            backgroundColor: "#6a7985",
          },
        },
      },
      legend: {
        padding: 2,
        icon: "rect", //  字段控制形状  类型包括 circle，rect,line，roundRect，triangle，diamond，pin，arrow，none
        itemWidth: 8, // 设置宽度
        itemHeight: 8, // 设置高度
        bottom: "2%",
        itemGap: 16,
        textStyle: {
          color: '#999'
        }
      },
      grid: {
        top: "10%",
        left: "0%",
        right: "0%",
        bottom: "15%",
        containLabel: true,
      },
      xAxis: [
        {
          type: "category",
          data: this.xAxis,
          axisLabel: {
            interval: 0,
            textStyle: {
              color: "#333",
            },
          },
          splitNumber: 0,
          axisTick: {
            show: false,
          },
        },
      ],
      yAxis: [
        {
          type: "value",
          axisLabel: {
            interval: 0,
            textStyle: {
              color: "#333",
            },
          },
          splitLine: {
            show: true,
            //  改变轴线颜色
            lineStyle: {
              width: 0.5,
              // 使用深浅的间隔色
              color: ["#e0e0e0"],
            },
          },
        },
      ],
      series: [
        {
          name: "数量",
          type: "line",
          smooth: true,
          lineStyle: {
            width: 0,
          },
          showSymbol: true,
          symbolSize: 5,
          symbol: "circle",
          areaStyle: {
            opacity: 1,
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: "rgba(66, 133, 244,0.6)",
              },
              {
                offset: 1,
                color: "rgba(66, 133, 244,0)",
              },
            ]),
          },
          emphasis: {
            focus: "series",
          },
          data: this.series,
        },

      ],
    }

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
  }
};
</script>

<style scoped>
/* 你可以在这里添加一些CSS样式 */
</style>
